class Stack:
    def __init__(self):
        self.items = []

    def push(self, item):
        self.items.append(item)

    def pop(self):
        if not self.is_empty():
            return self.items.pop()
        return None

    def is_empty(self):
        return len(self.items) == 0

    def peek(self):
        if not self.is_empty():
            return self.items[-1]
        return None

def calculate(s):
    """栈实现简单计算器（仅支持+、-、数字）"""
    stack = Stack()
    num = 0
    sign = '+'  # 初始符号为+
    s += '+'    # 末尾添加+，确保最后一个数字被处理
    for char in s:
        if char.isdigit():
            num = num * 10 + int(char)
        elif char in '+-':
            if sign == '+':
                stack.push(num)
            else:
                stack.push(-num)
            sign = char
            num = 0
    # 栈中所有数求和
    result = 0
    while not stack.is_empty():
        result += stack.pop()
    return result

# 测试
if __name__ == "__main__":
    print(calculate("1+2+3"))   # 输出: 6
    print(calculate("10-5+2"))  # 输出: 7
    print(calculate("3"))       # 输出: 3